package com.hiultra.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.ObjectUtil;
import com.hiultra.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.archive.domain.ArchiveUploadTaskBox;
import com.hiultra.archive.service.IArchiveUploadTaskBoxService;
import com.hiultra.common.utils.poi.ExcelUtil;
import com.hiultra.common.core.page.TableDataInfo;

/**
 * 转存档案盒Controller
 *
 * @author paidaxing
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/archive/ArchiveUploadTaskBox")
public class ArchiveUploadTaskBoxController extends BaseController
{
    @Autowired
    private IArchiveUploadTaskBoxService archiveUploadTaskBoxService;
    /**
     * 查询转存档案盒列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveUploadTaskBox:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveUploadTaskBox archiveUploadTaskBox)
    {
        startPage();
        List<ArchiveUploadTaskBox> list = archiveUploadTaskBoxService.selectArchiveUploadTaskBoxList(archiveUploadTaskBox);
        return getDataTable(list);
    }

    /**
     * 导出转存档案盒列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveUploadTaskBox:export')")
    @Log(title = "转存档案盒", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveUploadTaskBox archiveUploadTaskBox)
    {
        List<ArchiveUploadTaskBox> list = archiveUploadTaskBoxService.selectArchiveUploadTaskBoxList(archiveUploadTaskBox);
        ExcelUtil<ArchiveUploadTaskBox> util = new ExcelUtil<ArchiveUploadTaskBox>(ArchiveUploadTaskBox.class);
        util.exportExcel(response, list, "转存档案盒数据");
    }

    /**
     * 获取转存档案盒详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveUploadTaskBox:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(archiveUploadTaskBoxService.selectArchiveUploadTaskBoxById(id));
    }

    /**
     * 新增转存档案盒
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveUploadTaskBox:add')")
    @Log(title = "转存档案盒", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveUploadTaskBox archiveUploadTaskBox)
    {
        return toAjax(archiveUploadTaskBoxService.insertArchiveUploadTaskBox(archiveUploadTaskBox));
    }

    /**
     * 修改转存档案盒
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveUploadTaskBox:edit')")
    @Log(title = "转存档案盒", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveUploadTaskBox archiveUploadTaskBox)
    {
        return toAjax(archiveUploadTaskBoxService.updateArchiveUploadTaskBox(archiveUploadTaskBox));
    }

    /**
     * 删除转存档案盒
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveUploadTaskBox:remove')")
    @Log(title = "转存档案盒", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(archiveUploadTaskBoxService.deleteArchiveUploadTaskBoxByIds(ids));
    }

    /**
     * 修改转入转出状态
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveUploadTaskBox:updateArchiveUploadTaskBoxStatus')")
    @Log(title = "修改转入转出状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateArchiveUploadTaskBoxStatus")
    public AjaxResult updateArchiveUploadTaskBoxStatus(@RequestParam("taskId") String taskId,@RequestParam("ids") String[] ids, @RequestParam("")String status) {

        if(ObjectUtil.isNull(taskId)){
            return AjaxResult.error("转存任务信息为空，请检查重试！");
        }
        if(ids == null || ids.length<3){
            return AjaxResult.error("传入参数错误！");
        }
        return toAjax(archiveUploadTaskBoxService.updateArchiveUploadTaskBoxStatus(taskId,ids, status));
    }

}
